﻿using System;
using CDOP.Model;

namespace CDOP.Shared
{
    public partial class Site2 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
                if (Session["LoggedUser"] == null)
                {
                    hrefLogin.Visible = true;
                    lblWelcome.Visible = false;
                    lnkBtnLogOut.Visible = false;
                    dvMenu.Visible = false;
                }
                else
                {
                    hrefLogin.Visible = false;
                    lblWelcome.Visible = true;
                    var loggedUser = (UserDetails)Session["LoggedUser"];
                    lblWelcome.Text = string.Format("Welcome {0} {1}", loggedUser.First_Name, loggedUser.Last_name);
                    lnkBtnLogOut.Visible = true;
                    if (loggedUser.UserType.Type.ToLower() == "admin")
                    {
                        liAddUser.Visible = true;
                        liAdmin.Visible = true;
                    }
                    else
                    {
                        liAddUser.Visible = false;
                        liAdmin.Visible = false;
                    }
                }
            //}
        }

        protected void LnkBtnLogOutClick(object sender, EventArgs e)
        {
            Session["LoggedUser"] = null;
            Response.Redirect("Login.aspx");
        }
    }
}
